package com.vladmr.sleepytimepicker;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class AppPreferences {
	private static final String APP_SHARED_PREFS = "com.vladmr.sleepytimepicker";
	private SharedPreferences appSharedPrefs;
	private Editor prefsEditor;

	// application preferences:
	// stage_hour, stage_minute - base, one sleep stage duration;
	// alarm_hour, alarm_minute - alarm time
	// offset_sleep_hour, offset_sleep_minute - in ChooseWakeupActivity, go to sleep after this time

	public AppPreferences(Context context) {
		this.appSharedPrefs = context.getSharedPreferences(APP_SHARED_PREFS,
				Activity.MODE_PRIVATE);
		this.prefsEditor = appSharedPrefs.edit();
	}

	public int getStageHour() {
		return appSharedPrefs.getInt("stage_hour", 1);
	}

	public int getStageMinute() {
		return appSharedPrefs.getInt("stage_minute", 30);
	}
	
	public int getOffsetHour() {
		return appSharedPrefs.getInt("offset_sleep_hour", 0);
	}

	public int getOffsetMinute() {
		return appSharedPrefs.getInt("offset_sleep_minute", 10);
	}
	
	public void setOffset(int hour, int minute) {
		if ((hour >= 0) && (hour < 24) && (minute >= 0) && (minute < 60)) {
			prefsEditor.putInt("offset_sleep_hour", hour);
			prefsEditor.putInt("offset_sleep_minute", minute);
			prefsEditor.commit();
		}
	}

	public int getAlarmHour() {
		return appSharedPrefs.getInt("alarm_hour", 4);
	}

	public int getAlarmMinute() {
		return appSharedPrefs.getInt("alarm_minute", 0);
	}
	
	public void setAlarm(int hour, int minute) {
		if ((hour >= 0) && (hour < 24) && (minute >= 0) && (minute < 60)) {
			prefsEditor.putInt("alarm_hour", hour);
			prefsEditor.putInt("alarm_minute", minute);
			prefsEditor.commit();
		}
	}
}
